﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using yiCommerce.Core;
using yiCommerce.Core.Helper;
using yiCommerce.Service.Loggings;
using yiCommerce.Service.Products;

namespace yiCommerce.Admin.Controllers.api
{
    public class ProductVariantApiController : ApiController
    {

        private IProductService _productService;

        private readonly IWorkContext _workContext;
        private IActivityService _activityService;


        public ProductVariantApiController(IProductService productService, IWorkContext workContext, IActivityService activityService)
        {
            _productService = productService;
            _workContext = workContext;
            _activityService = activityService;
        }

       

        public ProductVariantInfoSaveResult InsertProductVariantInfo(ProductVariantInfoSaveRequest request)
        {
            var result = new ProductVariantInfoSaveResult();


            try
            {

                var productVariantId = _productService.InsertProductVariantInfo(request.ProductId, request.Name,
                     request.Sku, request.Price, request.DisplayOrder, request.StockQuantity, request.PictureId, request.Published);


                result.Status = "0";
                result.Id = productVariantId;

                _activityService.InsertActivity("InsertProductVariantInfo", JsonHelper.ToJson(request), _workContext.CurrentCustomer);
                //SuccessNotification(_localizationService.GetResource("Admin.Catalog.Products.Added"));
                return result;
            }
            catch (Exception e)
            {
                result.Status = "1";
                result.Message = e.ToString();
                return result;
            }
        }
    }
}
